package gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

class ImagePanel  extends JPanel {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	BufferedImage image;
    Dimension size = new Dimension();

    public ImagePanel(BufferedImage bImage) {
    	image = bImage;
    	if (image != null)
    		size.setSize(image.getWidth(), image.getHeight());
    }

    protected void paintComponent(Graphics g) {
        // Center image in this component.
        int x = (getWidth() - size.width)/2;
        int y = (getHeight() - size.height)/2;
        g.drawImage(image, x, y, this);
    }

    /**
     * This method handles the communication of
     * size requirements with the parent JScrollPane.
     */
    public Dimension getPreferredSize() {
        return size;
    }

}